package fms.models;
 
import java.util.List;
 
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import fms.classes.Account2;
 
 
public class Account2DAO {
 
    private SqlSessionFactory sqlSessionFactory;
 
    public Account2DAO(){
    	try{
    		sqlSessionFactory = MyBatisSqlConnection.getSqlSessionFactory();
    	}catch(Exception e) {
    		System.out.println("failed to get sqlSessionFactory");
    	}
    }
 
    /**Returns the list of all Account2 instances from the database*/
    @SuppressWarnings("unchecked")
    public List<Account2> selectAll(){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            List<Account2> list = session.selectList("Account2.getAll");
            return list;
        } finally {
            session.close();
        }
    }
 
    /**Returns a Account2 instance from the database*/
    public Account2 selectById(int account_id){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            Account2 account2 = (Account2) session.selectOne("Account2.getById",account_id);
            return account2;
        } finally {
            session.close();
        }
    }
 
    /**Updates an instance of Account2 in the database*/
    public void update(Account2 account2){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("Account2.update", account2);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Insert an instance of Account2 into the database*/
    public void insert(Account2 account2){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.insert("Account2.insert", account2);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Delete an instance of Account2 from the database*/
    public void delete(int account_id){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.delete("Account2.deleteById", account_id);
            session.commit();
        } finally {
            session.close();
        }
    }
}